<?php

namespace App\Http\Controllers;

use Carbon\Carbon;
use Illuminate\Http\Request;

/**
 * 关注相关
 * Class FollowController
 * @package App\Http\Controllers
 */
class TestController extends Controller{
    /**
     * 关注/取消关注分类
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function index(){
        dd(Carbon::now()->subHours(rand(1,10)));
    }

    protected function getComments($comment_id,$cursor= 0){
        $vid = 'p07500hsant';
        $url = 'https://ncgi.video.qq.com/fcgi-bin/video_comment_id?otype=json&callback=jQuery19107498598488382213_1542096743408&op=3&vid='.$vid;
        $res = $this->httpsRequest($url);
        $res = str_replace('jQuery19107498598488382213_1542096743408(', '', $res);
        $res = rtrim($res, ")");
        $res = json_decode($res, true);
        $comment_id = $res['comment_id'];
        if($comment_id){
            $comment = $this->getComments($comment_id,0);
        }
        $link = 'https://video.coral.qq.com/varticle/'.$comment_id.'/comment/v2?callback=_varticle'.$comment_id.'commentv2&orinum=40&oriorder=o&pageflag=1&cursor='.$cursor.'&scorecursor=0&orirepnum=2&reporder=o&reppageflag=1&source=9&_=1542098264908';
        $result = $this->httpsRequest($link);
        $result = str_replace('\n', '', $result);
        $result = str_replace('_varticle'.$comment_id.'commentv2(', '', $result);
        $result = rtrim($result, ")");
        $result = json_decode($result, true);
//        $data = ;//评论数据
//        $lastPage = $result['data']['last'];//获取下一页
//        $hasnext = $result['data']['hasnext'];//是否存在下一页
//        dd($result);
//        if($hasnext){
//            return $this->getComments($comment_id,$lastPage,$data);
//        }
        return $result['data']['oriCommList'];
    }


}
